<%--
  Created by IntelliJ IDEA.
  User: samsung
  Date: 2019/9/14
  Time: 13:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注册</title>
    <script src="/bootstrap/js/jquery.min.js"></script>
    <script src="/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css">

</head>
<body>

<div class="container">
    <div class="panel panel-success">
        <div class="panel-heading panel-title text-center">
            <h2>欢迎注册</h2>
        </div>
        <div class="panel-body">
            <form action="/users/reg" class="form-horizontal">
                <div class="form-group">
                    <label for="" class="col-md-3 text-right">用户名:</label>
                    <div class="col-md-6">
                        <input type="text" name="username" id="username" required class="form-control" placeholder="请输入用户名...">
                    </div>
                </div>
                <div class="form-group">
                    <label for="" class="col-md-3 text-right">密 码 :</label>
                    <div class="col-md-6">
                        <input type="password" name="password" minlength="6" maxlength="18" required class="form-control" placeholder="请输入密码...">
                    </div>
                </div>
                <div class="form-group" style="align-content: center ">
                    <label for="" class="col-md-3 text-right">角 色 :</label>
                    <div class="col-md-6">
                        <select class="form-control" id="role" name="role" >
                            <option value="teacher">老师</option>
                            <option value="student">学生</option>
                            <option value="manager">管理员</option>
                        </select>
                    </div>
                </div>
                <div class="form-group ">
                    <button type="submit" id="btn" class="btn btn-success col-lg-offset-3">注册</button>
                    <a href="/users" class="btn btn-info">已有账号</a>
                </div>
            </form>
        </div>
        <div class="panel-footer text-right">
            百度在线考试平台
        </div>
    </div>
</div>

</body>
<script>
    $(function (){
        $("#username").blur(function (){
            $.get("/users/validname",{username:$(this).val()},function (res){
                if (res!='0'){
                    alert("该账号已被注册！");
                    var button = document.getElementById("btn");
                    button.disabled = true;
                }
            })
        })
    })

    $(function (){
        $("#username").change(function (){
            $.get("/users/validname",{username:$(this).val()},function (res){
                if (res=='0'){
                    var button = document.getElementById("btn");
                    button.disabled = false;
                }
            })
        })
    })
</script>
</html>
